﻿package mortal.game.view.copy.groupCopy.view.singleCopyPanel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.groupCopy.view.*;
    import mortal.mvc.core.*;

    public class SingleCopyRender extends GCellRenderer
    {
        private var _tcopy:TCopy;
        private var _mapIcon:GImageBitmap;
        private var _title:GImageBitmap;
        private var _currnteCopyIcon:GBitmap;
        private var _firstBloodPanel:FirstBloodRewardPanel;
        private var _selectBg:ScaleBitmap;

        public function SingleCopyRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._mapIcon = UIFactory.gImageBitmap("", 3, 3, this);
            this._currnteCopyIcon = UIFactory.gBitmap("", 175, 10, this);
            this._title = UIFactory.gImageBitmap("", 20, 20, this);
            LoaderHelp.addResCallBack(ResFileConst.groupCopy, this.showSkin);
            this._selectBg = UIFactory.bg(0, 0, 305, this.height, this, ImagesConst.ForgingSelectBg);
            NetDispatcher.addCmdListener(ServerCommand.CopyFirstBloodRewardUpdate, this.updateFirstBloodItem);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._mapIcon.dispose(param1);
            this._mapIcon = null;
            this._currnteCopyIcon.dispose(param1);
            this._currnteCopyIcon = null;
            this._title.dispose(param1);
            this._title = null;
            if (this._firstBloodPanel)
            {
                this._firstBloodPanel.dispose(param1);
                this._firstBloodPanel = null;
            }
            this._selectBg.dispose(param1);
            this._selectBg = null;
            NetDispatcher.removeCmdListener(ServerCommand.CopyFirstBloodRewardUpdate, this.updateFirstBloodItem);
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            if (param1)
            {
                this._selectBg.visible = true;
            }
            else
            {
                this._selectBg.visible = false;
            }
            return;
        }// end function

        private function updateFirstBloodItem(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.copy.copyFirstBloodDic[this._tcopy.code];
            if (_loc_2 == ECopyFBType._ECopyFBTypeHadGet)
            {
                if (this._firstBloodPanel)
                {
                    this._firstBloodPanel.dispose();
                    this._firstBloodPanel = null;
                }
            }
            else
            {
                if (this._firstBloodPanel == null)
                {
                    this._firstBloodPanel = UICompomentPool.getUICompoment(FirstBloodRewardPanel);
                    this._firstBloodPanel.x = 190;
                    this._firstBloodPanel.y = 5;
                    this.addChild(this._firstBloodPanel);
                }
                this._firstBloodPanel.copyCode = this._tcopy.code;
                this._firstBloodPanel.type = _loc_2;
            }
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._currnteCopyIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GroupCopyFlag);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            this._tcopy = param1.tCopy;
            this._currnteCopyIcon.visible = Cache.instance.group.isInCopyGroup && Cache.instance.group.sgroup.copyCode == this._tcopy.code;
            this._mapIcon.bitmapData = null;
            this._mapIcon.imgUrl = "singleCopyIcon_" + this._tcopy.icon + ".png";
            this._title.imgUrl = "singleCopyTitle_" + this._tcopy.icon + ".png";
            if (this._tcopy.enterMinLevel <= _loc_2 && _loc_2 <= this._tcopy.enterMaxLevel)
            {
                this.filters = [];
            }
            else
            {
                this.filters = [FilterConst.colorFilter2];
            }
            this.updateFirstBloodItem();
            return;
        }// end function

    }
}
